<?php
namespace App\Api;

use App\Domain\UserReportClassifyDomain;
use PhalApi\Api;
use App\Domain\Video as Domain_Video;
use function PhalApi\DI;
use function PhalApi\T;

/**
 * 视频
 */

class Video extends Api {

	public function getRules() {
        return array(
            'myVideo' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'status' => array('name' => 'status', 'type' => 'int', 'default'=>'', 'desc' => '视频状态'),
				'p' => array('name' => 'p', 'type' => 'int', 'desc' => '页码'),
			),
            
            'getFee' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
			),
            'setVideo' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'title' => array('name' => 'title', 'type' => 'string', 'desc' => '标题'),
				'thumb' => array('name' => 'thumb', 'type' => 'string', 'desc' => '封面'),
				'href' => array('name' => 'href', 'type' => 'string', 'desc' => '视频'),
				'musicid' => array('name' => 'musicid', 'type' => 'int', 'desc' => '音乐ID，0未选'),
				'isprivate' => array('name' => 'isprivate', 'type' => 'int', 'desc' => '是否私密，0否1是'),
				'coin' => array('name' => 'coin', 'type' => 'int', 'desc' => '价格'),
				'sign' => array('name' => 'sign', 'type' => 'string', 'desc' => '签名 uid   thumb   href   isprivate'),
			),
            
            'setPublic' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'desc' => '视频ID'),
			),
            
            'addView' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'desc' => '视频ID'),
                'sign' => array('name' => 'sign', 'type' => 'string', 'desc' => '签名 uid  videoid'),
			),
            'addLike' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'desc' => '视频ID'),
                'sign' => array('name' => 'sign', 'type' => 'string', 'desc' => '签名 uid  videoid'),
			),
            'addShare' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'desc' => '视频ID'),
                'sign' => array('name' => 'sign', 'type' => 'string', 'desc' => '签名 uid  videoid'),
			),
            
            'delVideo' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'desc' => '视频ID'),
			),
            
            'setReport' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'desc' => '视频ID'),
				'content' => array('name' => 'content', 'type' => 'string', 'desc' => '内容'),
                'sign' => array('name' => 'sign', 'type' => 'string', 'desc' => '签名  uid   video  content'),
			),
            
            'getHomeVideo' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'desc' => '主播ID'),
				'p' => array('name' => 'p', 'type' => 'int', 'desc' => '页码'),
			),
            
            'buyVideo' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'videoid' => array('name' => 'videoid', 'type' => 'int', 'desc' => '视频ID'),
			),

            'getRecommendVideos'=>array(
                'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
                'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
                'p' => array('name' => 'p', 'type' => 'int', 'desc' => '页码'),
            ),

            'setComment' => array(
                'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
                'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户Token'),
                'videoid' => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
                'touid' => array('name' => 'touid', 'type' => 'int', 'default'=>0, 'desc' => '回复的评论UID'),
                'commentid' => array('name' => 'commentid', 'type' => 'int',  'default'=>0,  'desc' => '回复的评论commentid'),
                'parentid' => array('name' => 'parentid', 'type' => 'int',  'default'=>0,  'desc' => '回复的评论ID'),
                'content' => array('name' => 'content', 'type' => 'string',  'default'=>'', 'desc' => '内容'),
                'at_info'=>array('name'=>'at_info','type'=>'string','desc'=>'被@的用户json信息'),
            ),

            'getComments' => array(
                'uid' => array('name' => 'uid', 'type' => 'int','desc' => '用户ID'),
                'videoid' => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
                'p' => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default'=>1, 'desc' => '页数'),
            ),

            'getReplys' => array(
                'uid' => array('name' => 'uid', 'type' => 'int',  'require' => true, 'desc' => '用户ID'),
                'commentid' => array('name' => 'commentid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '评论ID'),
                'p' => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default'=>1, 'desc' => '页数'),
            ),

            'delComments' => array(
                'uid' => array('name' => 'uid', 'type' => 'int','desc' => '用户ID'),
                'token' => array('name' => 'token', 'type' => 'string', 'require' => false, 'desc' => '用户Token'),
                'videoid' => array('name' => 'videoid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '视频ID'),
                'commentid' => array('name' => 'commentid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '评论ID'),
                'commentuid' => array('name' => 'commentuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '评论者用户ID'),  
            ),

            'addCommentLike' => array(
                'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
                'token' => array('name' => 'token', 'type' => 'string', 'require' => false, 'desc' => '用户Token'),
                'commentid' => array('name' => 'commentid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '评论/回复 ID'),
            ),
            'getReport' => [
                'langId' => ['name' => 'langId', 'type' => 'int','desc' => '语种ID']
            ],
            'viewVideo' => [
                'videoId' => ['name' => 'videoId' ,'type' => 'int', 'desc' => '视频ID']
            ]
            
        );
	}
	
    /**
     * 我的视频
     * @desc 用于获取我的视频
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[].id 视频ID  
     * @return string info[].title 标题  
     * @return string info[].thumb 封面  
     * @return string info[].href 链接  
     * @return string info[].likes 点赞数
     * @return string info[].views 观看数  
     * @return string info[].shares 分享数
     * @return string info[].comments 评论数
     * @return string info[].isprivate 是否私密，0否1是  
     * @return string info[].coin 价格
     * @return string info[].status 审核状态，0审核中，1通过，2拒绝
     * @return string info[].reason 失败原因
     * @return object info[].userinfo 用户信息
     * @return string info[].userinfo.id 用户ID  
     * @return string info[].userinfo.user_nickname 昵称
     * @return string info[].userinfo.avatar 头像
     * @return string info[].userinfo.avatar_thumb 小头像
     * @return string msg 提示信息
     */
	public function myVideo() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$status=\App\checkNull($this->status);
		$p=\App\checkNull($this->p);
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        
        $domain = new Domain_Video();
		$list=$domain->myVideo($uid,$status,$p);
        
        $rs['info']=$list;
        
        return $rs;
	}

    /**
     * 视频价格
     * @desc 用于获取私密视频价格
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[0].tips 温馨提示
     * @return array info[0].list 价格列表
     * @return string info[0].list[].coin 价格
     * @return string info[0].list[].level 等级
     * @return string msg 提示信息
     */
	public function getFee() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        $userinfo=\App\getUserInfo($uid);
        
        $domain = new Domain_Video();
		$list=$domain->getFee();
        
        foreach($list as$k=>$v){
            $v['canselect']='0';
            if($v['level']<=$userinfo['level_anchor']){
                $v['canselect']='1';
            }
            $list[$k]=$v;
        }
        $info['list']=$list;
        $info['tips']=\PhalApi\T('温馨提示：私密视频为一次性付费，终身免费；会员用户可免费查看私密视频');
        
        $rs['info'][0]=$info;
        
        return $rs;
	}

    /**
     * 视频价格说明
     * @desc 用于查看价格说明
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[].thumb 等级图标
	 * @return string info[].coin 价格
     * @return string msg 提示信息
     */
	public function getFeeInfo() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        $domain = new Domain_Video();
        
        $levellist = \App\getLevelanchorList();
		$list=$domain->getFee();
        foreach($levellist as $k=>$v ){
            $v['coin']='0';
            foreach($list as $k1=>$v1){
                if($v['level']>=$v1['level']){
                    $v['coin']=$v1['coin'];
                }
            }
            unset($v['id']);
            unset($v['level_up']);
            
            $levellist[$k]=$v;
        }
        $rs['info']=$levellist;
        
        return $rs;
	}

    /**
     * 发布视频
     * @desc 用于用户发布视频
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string msg 提示信息
     */
	public function setVideo() {
        
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$title=\App\checkNull($this->title);
		$thumb=\App\checkNull($this->thumb);
		$href=\App\checkNull($this->href);
		$musicid=\App\checkNull($this->musicid);
		$isprivate=\App\checkNull($this->isprivate);
		$coin=\App\checkNull($this->coin);
		$sign=\App\checkNull($this->sign);
        
        if($uid<1 || $token=='' || $thumb=='' || $href=='' ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
        
        $checkdata=array(
            'uid'=>$uid,
            'thumb'=>$thumb,
            'href'=>$href,
            'isprivate'=>$isprivate,
        );
        
        $issign=\App\checkSign($checkdata,$sign);
        if(!$issign){
            $rs['code']=1002;
			$rs['msg']=\PhalApi\T('签名错误');
			return $rs;	
        }
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        $data=[
            'uid'=>$uid,
            'title'=>$title,
            'thumb'=>$thumb,
            'href'=>$href,
            'musicid'=>$musicid,
            'isprivate'=>$isprivate,
            'coin'=>$coin,
        ];
        
        $domain = new Domain_Video();
		$result=$domain->setVideo($data);
        
		return $result;
        
	}

    /**
     * 设为公开
     * @desc 用于用户把私密视频设置为公开
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string msg 提示信息
     */
	public function setPublic() {
        
        $rs = array('code' => 0, 'msg' => \PhalApi\T('设置成功'), 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$videoid=\App\checkNull($this->videoid);
        
        if($uid<1 || $token=='' || $videoid <1 ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
        
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        $domain = new Domain_Video();
		$result=$domain->setPublic($uid,$videoid);
        
		return $rs;
        
	}
    
    /**
     * 观看
     * @desc 用于更新视频观看量
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[].nums 数量
     * @return string msg 提示信息
     */
	public function addView() {
        
        $rs = array('code' => 0, 'msg' => \PhalApi\T('操作成功'), 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$videoid=\App\checkNull($this->videoid);
		$sign=\App\checkNull($this->sign);
        
        if($uid<1 || $token=='' || $videoid <1 ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
        
        $checkdata=array(
            'uid'=>$uid,
            'videoid'=>$videoid,
        );
        
        $issign=\App\checkSign($checkdata,$sign);
        if(!$issign){
            $rs['code']=1002;
			$rs['msg']=\PhalApi\T('签名错误');
			return $rs;	
        }
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        
        $domain = new Domain_Video();
		$result=$domain->addView($uid,$videoid);
        
		return $result;
        
	}

    /**
     * 点赞
     * @desc 用于更新视频点赞
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[0].islike 是否点赞，0否1是
     * @return string info[0].nums 数量
     * @return string msg 提示信息
     */
	public function addLike() {
        
        $rs = array('code' => 0, 'msg' => \PhalApi\T('操作成功'), 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$videoid=\App\checkNull($this->videoid);
		$sign=\App\checkNull($this->sign);
        
        if($uid<1 || $token=='' || $videoid <1 ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
        
        $checkdata=array(
            'uid'=>$uid,
            'videoid'=>$videoid,
        );
        
        $issign=\App\checkSign($checkdata,$sign);
        if(!$issign){
            $rs['code']=1002;
			$rs['msg']=\PhalApi\T('签名错误');
			return $rs;	
        }
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        
        $domain = new Domain_Video();
		$result=$domain->addLike($uid,$videoid);
        
		return $result;
        
	}

    /**
     * 分享
     * @desc 用于更新视频分享数
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[0].nums 数量 
     * @return string msg 提示信息
     */
	public function addShare() {
        
        $rs = array('code' => 0, 'msg' => \PhalApi\T('操作成功'), 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$videoid=\App\checkNull($this->videoid);
		$sign=\App\checkNull($this->sign);
        
        if($uid<1 || $token=='' || $videoid <1 ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
        
        $checkdata=array(
            'uid'=>$uid,
            'videoid'=>$videoid,
        );
        
        $issign=\App\checkSign($checkdata,$sign);
        if(!$issign){
            $rs['code']=1002;
			$rs['msg']=\PhalApi\T('签名错误');
			return $rs;	
        }
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        
        $domain = new Domain_Video();
		$result=$domain->addShare($uid,$videoid);
        
		return $result;
	}
    

    /**
     * 删除视频
     * @desc 用于用户删除视频
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string msg 提示信息
     */
	public function delVideo() {
        
        $rs = array('code' => 0, 'msg' => \PhalApi\T('操作成功'), 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$videoid=\App\checkNull($this->videoid);
        
        if($uid<1 || $token=='' || $videoid <1 ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        
        $domain = new Domain_Video();
		$result=$domain->delVideo($uid,$videoid);
        
		return $result;
        
	}

    /**
     * 举报分类
     * @desc 用于举报分类
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[].name 分类名 
     * @return string msg 提示信息
     */
	public function getReport() {
        
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        
//        $domain = new Domain_Video();
//		$list=$domain->getReport();
        $list = UserReportClassifyDomain::getReportClassify(2,$this->langId);
        
        $rs['info']=$list;
        
		return $rs;
        
	}
    
    /**
     * 举报
     * @desc 用于用户举报视频
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string msg 提示信息
     */
	public function setReport() {
        
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$videoid=\App\checkNull($this->videoid);
		$content=\App\checkNull($this->content);
		$sign=\App\checkNull($this->sign);
        
        if($uid<1 || $token=='' || $videoid <1 || $content==''){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
        
        $checkdata=array(
            'uid'=>$uid,
            'videoid'=>$videoid,
            'content'=>$content,
        );
        
        $issign=\App\checkSign($checkdata,$sign);
        if(!$issign){
            $rs['code']=1002;
			$rs['msg']=\PhalApi\T('签名错误');
			return $rs;	
        }
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        
        $domain = new Domain_Video();
		$result=$domain->setReport($uid,$videoid,$content);
        
		return $result;
        
	}

    /**
     * 个人视频
     * @desc 用于获取个人主页视频
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[].id 视频ID  
     * @return string info[].title 标题  
     * @return string info[].thumb 封面  
     * @return string info[].href 链接  
     * @return string info[].likes 点赞数
     * @return string info[].views 观看数  
     * @return string info[].shares 分享数
     * @return string info[].comments 评论数
     * @return string info[].isprivate 是否私密，0否1是  
     * @return string info[].coin 价格  
     * @return string info[].islike 是否点赞，0否1是  
     * @return string info[].cansee 是否能看，0否1是  
     * @return object info[].userinfo 用户信息
     * @return string info[].userinfo.id 用户ID  
     * @return string info[].userinfo.user_nickname 昵称
     * @return string info[].userinfo.avatar 头像
     * @return string info[].userinfo.avatar_thumb 小头像
     * @return string msg 提示信息
     */
	public function getHomeVideo() {
        
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$liveuid=\App\checkNull($this->liveuid);
		$p=\App\checkNull($this->p);
        
        if($uid<1 || $token=='' || $liveuid <1 ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }

        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        $domain = new Domain_Video();
		$result=$domain->getHomeVideo($uid,$liveuid,$p);
        
		return $result;
        
	}

    /**
     * 付费
     * @desc 用于视频付费
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[0].href 视频链接
     * @return string msg 提示信息
     */
	public function buyVideo() {
        
        $rs = array('code' => 0, 'msg' => \PhalApi\T('操作成功'), 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$videoid=\App\checkNull($this->videoid);
        
        if($uid<1 || $token=='' || $videoid <1 ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }

        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        
        $domain = new Domain_Video();
		$result=$domain->buyVideo($uid,$videoid);

		return $result;
        
	}

    /**
     * 获取首页推荐视频列表
     * @desc 用于获取首页推荐视频列表
     * @return int code 状态码,0表示成功
     * @return string msg 提示信息
     * @return array info 返回数据
     * @return array info[]['userinfo'] 返回用户信息
     * @return string info[]['avatar'] 返回用户头像
     * @return string info[]['user_nickname'] 返回用户昵称
     * @return string info[]['title'] 返回视频标题
     * @return string info[]['href'] 返回视频链接
     * @return int info[]['isprivate'] 返回视频是否私有收费
     * @return int info[]['coin'] 返回视频收费价格
     * @return int info[]['cansee'] 返回视频是否可看
     * @return int info[]['islike'] 返回视频是否点赞
     * @return int info[]['comments'] 返回视频评论数
     */
    public function getRecommendVideos(){
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        
        $uid=\App\checkNull($this->uid);
        $token=\App\checkNull($this->token);
        $p=\App\checkNull($this->p);

        $domain=new Domain_Video();
        $res=$domain->getRecommendVideos($uid,$p);
        $rs['info']=$res;
        return $rs;
    }


    /**
     * 评论/回复
     * @desc 用于用户评论/回复 别人视频
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return int info[0].isattent 对方是否关注我
     * @return int info[0].u2t 我是否拉黑对方
     * @return int info[0].t2u 对方是否拉黑我
     * @return int info[0].comments 评论总数
     * @return int info[0].replys 回复总数
     * @return string msg 提示信息
     */
    public function setComment() {
        $rs = array('code' => 0, 'msg' => \PhalApi\T('评论成功'), 'info' => array());
        
        $uid=\App\checkNull($this->uid);
        $token=\App\checkNull($this->token);
        $touid=\App\checkNull($this->touid);
        $videoid=\App\checkNull($this->videoid);
        $commentid=\App\checkNull($this->commentid);
        $parentid=\App\checkNull($this->parentid);
        $content=\App\checkNull($this->content);
        $at_info=$this->at_info;

        if(!$at_info){
            $at_info='';
        }
        
        $checkToken=\App\checkToken($uid,$token);
        if($checkToken==700){
            $rs['code'] = $checkToken;
            $rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
            return $rs;
        }
        $is_has_sensitive=\App\checkSensitiveWords($content);
        if($is_has_sensitive==1001){
            $rs['code'] = 1001;
            $rs['msg'] = \PhalApi\T('输入非法，请重新输入');
            return $rs;
        }
        
        if($commentid==0 && $commentid!=$parentid){
            $commentid=$parentid;
        }
        
        $data=array(
            'uid'=>$uid,
            'touid'=>$touid,
            'videoid'=>$videoid,
            'commentid'=>$commentid,
            'parentid'=>$parentid,
            'content'=>$content,
            'addtime'=>time(),
            'at_info'=>$at_info
        );

        $domain = new Domain_Video();
        $result = $domain->setComment($data);
        

        
        $info=array(
            'isattent'=>'0',
            'u2t'=>'0',
            't2u'=>'0',
            'comments'=>$result['comments'],
            'replys'=>$result['replys'],
        );
        if($touid>0){
            $isattent=\App\isAttention($touid,$uid);
            $u2t = \App\isBlack($uid,$touid);
            $t2u = \App\isBlack($touid,$uid);
            
            $info['isattent']=(string)$isattent;
            $info['u2t']=(string)$u2t;
            $info['t2u']=(string)$t2u;
        }
        
        $rs['info'][0]=$info;
        
        if($parentid!=0){
             $rs['msg']='回复成功';         
        }
        return $rs;
    }

    /**
     * 视频评论列表
     * @desc 用于获取视频评论列表
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[0].comments 评论总数
     * @return array info[0].commentlist 评论列表
     * @return object info[0].commentlist[].userinfo 用户信息
     * @return string info[0].commentlist[].datetime 格式后的时间差
     * @return string info[0].commentlist[].replys 回复总数
     * @return string info[0].commentlist[].likes 点赞数
     * @return string info[0].commentlist[].islike 是否点赞
     * @return array info[0].commentlist[].replylist 回复列表
     * @return string msg 提示信息
     */
    public function getComments() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());

        $uid=\App\checkNull($this->uid);
        $videoid=\App\checkNull($this->videoid);
        $p=\App\checkNull($this->p);

        $domain = new Domain_Video();
        $rs['info'][0] = $domain->getComments($uid,$videoid,$p);

        return $rs;
    }

    /**
     * 回复列表
     * @desc 用于获取视频评论列表
     * @return int code 操作码，0表示成功
     * @return array info 评论列表
     * @return object info[].userinfo 用户信息
     * @return string info[].datetime 格式后的时间差
     * @return object info[].tocommentinfo 回复的评论的信息
     * @return object info[].tocommentinfo.content 评论内容
     * @return string info[].likes 点赞数
     * @return string info[].islike 是否点赞
     * @return string msg 提示信息
     */
    public function getReplys() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());

        $uid=\App\checkNull($this->uid);
        $commentid=\App\checkNull($this->commentid);
        $p=\App\checkNull($this->p);

        $domain = new Domain_Video();
        $rs['info'] = $domain->getReplys($uid,$commentid,$p);

        return $rs;
    }

    /**
     * 删除评论
     * @desc 用于删除评论以及子级评论
     * @return int code 操作码，0表示成功
     * @return string msg 提示信息
     */
    public function delComments() {
        $rs = array('code' => 0, 'msg' => \PhalApi\T('删除成功'), 'info' => array());
        
        $uid=\App\checkNull($this->uid);
        $token=\App\checkNull($this->token);
        $videoid=\App\checkNull($this->videoid);
        $commentid=\App\checkNull($this->commentid);
        $commentuid=\App\checkNull($this->commentuid);


        $checkToken=\App\checkToken($uid,$token);
        if($checkToken==700){
            $rs['code'] = $checkToken;
            $rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
            return $rs;
        }
        
        $domain = new Domain_Video();
        $info = $domain->delComments($uid,$videoid,$commentid,$commentuid);
        
        if($info==1001){
            $rs['code'] = 1001;
            $rs['msg'] = \PhalApi\T('视频信息错误,请稍后操作~');
        }else if($info==1002){
            $rs['code'] = 1002;
            $rs['msg'] = \PhalApi\T('您无权进行删除操作~');
        }

        return $rs;
    }

    /**
     * 评论/回复 点赞
     * @desc 用于评论/回复 点赞数累计
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[0].islike 是否点赞 
     * @return string info[0].likes 点赞数量
     * @return string msg 提示信息
     */
    public function addCommentLike() {
        $rs = array('code' => 0, 'msg' => \PhalApi\T('点赞成功'), 'info' => array());

        $uid=\App\checkNull($this->uid);
        $token=\App\checkNull($this->token);
        $commentid=\App\checkNull($this->commentid);


        $checkToken=\App\checkToken($uid,$token);
        if($checkToken==700){
            $rs['code'] = $checkToken;
            $rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
            return $rs;
        }

        $domain = new Domain_Video();
        $res= $domain->addCommentLike($uid,$commentid);
        if($res==1001){
            $rs['code']=1001;
            $rs['msg']=\PhalApi\T('评论信息不存在');
            return $rs;
        }

        if(!$res['islike']){
            $rs['msg']=\PhalApi\T('取消点赞成功');
        }

        $rs['info'][0]=$res;

        return $rs;
    }

    /**
     * 更新视频浏览量
     * @return array
     */
    public function viewVideo()
    {
        if (empty($this->videoId)) {
            return [
                'code' => -1,
                'msg' => T("视频ID不能为空"),
                'info' => []
            ];
        }

        $video = DI()->notorm->video->where('id = '.$this->videoId)->fetchRow();

        if ($video) {
            $upData = [
                'views' => $video['views'] + 1,
            ];
            DI()->notorm->video->where('id = '.$this->videoId)->update($upData);
            return [
                'code' => 0,
                'msg' => T("操作成功")
            ];
        }
        return [
            'code' => -1,
            'msg' => T("视频不存在")
        ];
    }
    
}
